//
//  UserModel.m
//  YiXiu
//
//  Created by ZHY on 16/7/7.
//  Copyright © 2016年 zzz. All rights reserved.
//

#import "UserModel.h"
#import "MYSSerializeKit.h"

@implementation UserModel

+ (UserModel *)sharedUserModel
{
    static UserModel *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        if (YES) {
            sharedAccountManagerInstance = [[self alloc] init];
        }else{
            sharedAccountManagerInstance = nil;

        }
        
    });
    return sharedAccountManagerInstance;
}

//- (NSString *)name{
//    
//    return [NSString stringWithString:[_name stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//    
//}
//
//- (NSString *)sex{
//
//    return [NSString stringWithString:[_sex stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//    
//}

// 当这个类第一次用到的时候 会调这个方法 也只会调用一次
+ (void)initialize
{
    if (self == [UserModel class]) {
        
        // 解档：unarchover
        UserModel * model = [NSKeyedUnarchiver unarchiveObjectWithFile:UserPath];
        
        // 单例初始化复制
        [[UserModel sharedUserModel] setHeadImage:model.headImage];
        [[UserModel sharedUserModel] setName:[Tools replaceUnicode:model.name]];
        [[UserModel sharedUserModel] setSex:model.sex];
        [[UserModel sharedUserModel] setSexSelect:model.sexSelect];
        [[UserModel sharedUserModel] setMarried:model.married];
        [[UserModel sharedUserModel] setAge:model.age];
        [[UserModel sharedUserModel] setU_label:model.u_label];
        [[UserModel sharedUserModel] setUserID:model.userID];
        [[UserModel sharedUserModel] setIsLogin:model.isLogin];
        [[UserModel sharedUserModel] setU_id:model.u_id];
    }
}

//
//- (id)initWithCoder:(NSCoder *)aDecoder{
//     NSLog(@"initWithCoder");
//     self = [super init];
//     if(self != nil){
//        //一般我们将key定义成宏，这样就不会出错
//        _name = [[aDecoder decodeObjectForKey:@"name"] copy];
//        self.age = [aDecoder decodeObjectForKey:@"age"];
//        self.headImage = [aDecoder decodeObjectForKey:@"headImage"];
//        self.sex =[aDecoder decodeObjectForKey:@"sex"];
//        self.sexSelect =[aDecoder decodeObjectForKey:@"sexSelect"];
//         self.married =[aDecoder decodeObjectForKey:@"married"];
//         self.isLogin =[aDecoder decodeBoolForKey:@"isLogin"];
//        
//    }
//    return self;
//}
////归档时调用此方法
//- (void)encodeWithCoder:(NSCoder *)aCoder{
//     NSLog(@"encodeWithCoder");
//     [aCoder encodeObject:_name forKey:@"name"];//一般key和属性名是取一样的
//     [aCoder encodeObject:_age forKey:@"age"];
//     [aCoder encodeObject:_headImage forKey:@"headImage"];
//     [aCoder encodeObject:_sex forKey:@"sex"];
//     [aCoder encodeObject:_sexSelect forKey:@"sexSelect"];
//     [aCoder encodeObject:_married forKey:@"married"];
//     [aCoder encodeBool:_isLogin forKey:@"isLogin"];
//}

MJCodingImplementation

//MYSSERIALIZE_CODER_DECODER()




@end
